//
//  CellForExploreSectionZero.m
//  echo
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 Danny. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width / 414
#define HEIGHT [UIScreen mainScreen].bounds.size.height / 736

#import "CellForExploreSectionZero.h"
#import "ItemForExploreCollectionView.h"
#import "ModelForExploreCollectionView.h"
#import <SDWebImage/UIButton+WebCache.h>
#import <DKNightVersion.h>

@interface CellForExploreSectionZero ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain)UIView *viewForBack;
@property (nonatomic, retain)UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, retain)UICollectionView *collectionView;
@property (nonatomic, retain)NSArray *arrForModel;
@end

@implementation CellForExploreSectionZero

- (void)dealloc{
    [_viewForBack release];
    [_flowLayout release];
    [_arrForModel release];
    self.collectionView.delegate = nil;
    [_collectionView release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.viewForBack = [[UIView alloc]init];
        [self.contentView addSubview:self.viewForBack];
        [self.viewForBack release];
        [self handleNightModel];
    }
    return self;
}

- (void)handleNightModel{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    
    self.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);
    self.viewForBack.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);

}

- (void)createFlowLayout{
    
    self.flowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.flowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width - 10 * WIDTH - 15 * WIDTH * 5)/5, (self.contentView.frame.size.width - 10 * WIDTH - 15 * WIDTH * 5)/5 + 20 * HEIGHT);
    self.flowLayout.minimumInteritemSpacing = 15 * HEIGHT;
    self.flowLayout.minimumLineSpacing = 15 * WIDTH;
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.flowLayout.sectionInset = UIEdgeInsetsMake(10 * HEIGHT, 10 * WIDTH, 10 * HEIGHT, 10 * WIDTH);

    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, (self.contentView.frame.size.width - 10 * WIDTH - 15 * WIDTH * 5)/5 + 20 * HEIGHT + 20 * HEIGHT) collectionViewLayout:self.flowLayout];
    [self.viewForBack addSubview:self.collectionView];
    self.contentView.backgroundColor = [UIColor whiteColor];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    self.collectionView.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);
    

    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    [self.collectionView registerClass:[ItemForExploreCollectionView class] forCellWithReuseIdentifier:@"itemForCollectionView"];
    [self.collectionView release];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 15;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ItemForExploreCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"itemForCollectionView" forIndexPath:indexPath];
    
    if (indexPath.item == 0) {
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_yinyueleixing2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"音乐类型";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    }
    else if (indexPath.item == 1){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_qingxu2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"情绪";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 2){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_3d2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"3D听觉";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 3){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_yingshi2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"影视";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 4){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_ziran2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"自然";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 5){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_changjing2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"场景";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 6){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_ercy2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"二次元";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 7){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_gaoxiao2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"搞笑";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 8){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_fx_lb52x.png"] forState:UIControlStateNormal];
        cell.label.text = @"品牌";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 9){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_tech2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"创作";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 10){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_alt2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"另类";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 11){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_yule2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"娱乐";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 12){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_zhuanti2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"专题";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else if (indexPath.item == 13){
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/pd_xueshu2x.png"] forState:UIControlStateNormal];
        cell.label.text = @"学术";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }else{
        [cell.button sd_setBackgroundImageWithURL:[NSURL URLWithString:@"http://7xavig.com2.z0.glb.qiniucdn.com/new_channel_category/diantai.png"] forState:UIControlStateNormal];
        cell.label.text = @"电台";
        cell.label.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
        
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.viewForBack.frame = self.contentView.frame;

    [self createFlowLayout];

}

- (void)passDataArrForCollectionView:(NSArray *)arr{
    self.arrForModel = [NSArray arrayWithArray:arr];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
